<template>
  <el-dialog
   v-model="dialogVisible"
   title="编辑"
   :before-close="CloseDia"
   width="70%">
   <div class="diagnose-container">
     <el-form class="diagnose-form" :model="diagnose" ref="diagnoseRef" label-width="120px" :rules="diagnoseRules" label-position="left">
      <el-form-item label="id" v-if="false" prop="id">
         <el-input v-model="diagnose.id" name="id" />
      </el-form-item>
      <el-form-item label="姓名" prop="id">
         <el-input v-model="diagnose.patient.name" name="name"><template #append><el-button type="primary" @click="selectPatient">选择患者</el-button></template></el-input>
       </el-form-item>
       <el-form-item label="诊断名称" prop="diagnoseId">
         <el-select v-model="diagnose.diagnoseId" placeholder="" name="diagnoseId" clearable multiple style="width: 540px">
          <el-option value="慢性乙型病毒性肝炎" label="慢性乙型病毒性肝炎"/>
          <el-option value="乙型病毒性肝炎" label="乙型病毒性肝炎"/>
          <el-option value="乙型肝炎肝硬化" label="乙型肝炎肝硬化"/>
          <el-option value="乙型肝炎后肝硬化失代偿期" label="乙型肝炎后肝硬化失代偿期"/>
          <el-option value="乙型病毒性肝炎病原携带者" label="乙型病毒性肝炎病原携带者"/>
          <el-option value="非酒精性脂肪肝" label="非酒精性脂肪肝"/>
          <el-option value="脂肪肝" label="脂肪肝"/>
          <el-option value="酒精性脂肪肝" label="酒精性脂肪肝"/>
          <el-option value="肝细胞癌" label="肝细胞癌"/>
          <el-option value="自身免疫性肝炎" label="自身免疫性肝炎"/>
          <el-option value="自身免疫性肝硬化" label="自身免疫性肝硬化"/>
          <el-option value="原发性胆汁性肝硬化" label="原发性胆汁性肝硬化"/>
          <el-option value="Q热" label="Q热"/>
          <el-option value="艾滋病" label="艾滋病"/>
          <el-option value="发热待查" label="发热待查"/>
          <el-option value="乏力" label="乏力"/>
          <el-option value="腹痛" label="腹痛"/>
          <el-option value="肝豆状核变性" label="肝豆状核变性"/>
          <el-option value="肝功能不全" label="肝功能不全"/>
          <el-option value="肝内胆管癌" label="肝内胆管癌"/>
          <el-option value="肝内胆汁淤积症" label="肝内胆汁淤积症"/>
          <el-option value="肝囊肿" label="肝囊肿"/>
          <el-option value="肝区不适" label="肝区不适"/>
          <el-option value="肝衰竭" label="肝衰竭"/>
          <el-option value="肝性脑病" label="肝性脑病"/>
          <el-option value="肝移植状态" label="肝移植状态"/>
          <el-option value="肝硬化失代偿期" label="肝硬化失代偿期"/>
          <el-option value="肝占位性病变" label="肝占位性病变"/>
          <el-option value="肝肿瘤" label="肝肿瘤"/>
          <el-option value="高胆红素血症" label="高胆红素血症"/>
          <el-option value="高血压" label="高血压"/>
          <el-option value="高脂血症" label="高脂血症"/>
          <el-option value="黄疸" label="黄疸"/>
          <el-option value="急性黄疸型肝炎" label="急性黄疸型肝炎"/>
          <el-option value="急性戊型肝炎" label="急性戊型肝炎"/>
          <el-option value="酒精性肝硬化" label="酒精性肝硬化"/>
          <el-option value="慢加急性肝衰竭" label="慢加急性肝衰竭"/>
          <el-option value="慢性丙型病毒性肝炎" label="慢性丙型病毒性肝炎"/>
          <el-option value="梅毒" label="梅毒"/>
          <el-option value="皮肤感染" label="皮肤感染"/>
          <el-option value="妊娠状态" label="妊娠状态"/>
          <el-option value="腮腺炎" label="腮腺炎"/>
          <el-option value="失眠" label="失眠"/>
          <el-option value="水肿" label="水肿"/>
          <el-option value="糖耐量受损" label="糖耐量受损"/>
          <el-option value="体检" label="体检"/>
          <el-option value="戊型肝炎抗体阳性" label="戊型肝炎抗体阳性"/>
          <el-option value="消瘦" label="消瘦"/>
          <el-option value="药物性肝炎" label="药物性肝炎"/>
          <el-option value="晕厥" label="晕厥"/>
          <el-option value="直肠恶性肿瘤术后" label="直肠恶性肿瘤术后"/>
          <el-option value="转氨酶升高" label="转氨酶升高"/>
         </el-select>
       </el-form-item>
       <el-form-item label="就诊日期" prop="diagnoseTime">
        <el-col :span="12">
           <el-form-item prop="diagnoseTime">
             <el-date-picker
               v-model="diagnose.diagnoseTime"
               type="date"
               placeholder=""
               style="width: 100%"
             />
           </el-form-item>
         </el-col>
       </el-form-item>
       <el-form-item label="下次就诊日期" prop="nextDiagnoseTime">
          <el-col :span="12">
            <el-form-item prop="nextDiagnoseTime">
              <el-date-picker
                v-model="diagnose.nextDiagnoseTime"
                type="date"
                placeholder=""
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
       </el-form-item>
       <el-form-item label="短信模板" prop="remindSmsId">
          <el-select v-model="diagnose.remindSmsId" placeholder="" name="remindSmsId">
           <el-option value="1" label="模板一" />
           <el-option value="2" label="模板二" />
          </el-select>
       </el-form-item>
       <!-- 病史 -->
       <el-divider>病史</el-divider>
       <el-form-item label="主诉" prop="chiefComplaint">
         <el-input type="textarea" v-model="diagnose.chiefComplaint" name="chiefComplaint"/>
       </el-form-item>
       <el-form-item label="现病史" prop="nowHis">
         <el-input type="textarea" v-model="diagnose.nowHis" name="nowHis"/>
       </el-form-item>
       <el-form-item label="既往史" prop="pastHis">
         <el-input type="textarea" v-model="diagnose.pastHis" name="pastHis"/>
       </el-form-item>
       <el-form-item label="体格检查" prop="healthCheck">
         <el-input type="textarea" v-model="diagnose.healthCheck" name="healthCheck"/>
       </el-form-item>
       <!-- 治疗方案 -->
       <el-divider>治疗方案</el-divider>
       <el-table :data="diagnose.cures" border style="width: 100%">
        <el-table-column prop="medicine" label="药物名称" width="180">
          <template #default="scope">
            <el-input v-if="scope.row.edit" v-model="scope.row.medicine"></el-input>
            <span v-else>{{scope.row.medicine}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="dosage" label="单次剂量" width="180">
          <template #default="scope">
            <el-input v-if="scope.row.edit" v-model="scope.row.dosage"></el-input>
            <span v-else>{{scope.row.dosage}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="frequency" label="服用频次" width="180">
          <template #default="scope">
            <el-input v-if="scope.row.edit" v-model="scope.row.frequency"></el-input>
            <span v-else>{{scope.row.frequency}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="memo" label="备注" width="180">
          <template #default="scope">
            <el-input v-if="scope.row.edit" v-model="scope.row.memo"></el-input>
            <span v-else>{{scope.row.memo}}</span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="140">
          <template #default="scope">
           <el-button text type="danger" size="small" @click="deleteCures(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-form-item>
        <el-button type="primary" @click="createCure">新增</el-button>
      </el-form-item>
       <!-- 检验报告 -->
       <el-divider>检验检查报告</el-divider>
      <el-tabs v-model="activeName" class="demo-tabs" @tab-click="tabClick">
        <el-tab-pane label="检验" name="checkout">
          <el-form :model="diagnose.checkout" label-width="120px">
            <el-divider content-position="left">血常规</el-divider>
            <el-form-item label="白细胞计数">
              <el-input v-model="diagnose.checkout.白细胞计数" name="白细胞计数"/>
            </el-form-item>
            <el-form-item label="红细胞计数">
              <el-input v-model="diagnose.checkout.红细胞计数" name="红细胞计数"/>
            </el-form-item>
            <el-form-item label="血红蛋白">
              <el-input v-model="diagnose.checkout.血红蛋白" name="血红蛋白"/>
            </el-form-item>
            <el-form-item label="血小板">
              <el-input v-model="diagnose.checkout.血小板" name="血小板"/>
            </el-form-item>
            <el-divider content-position="left">肝功能</el-divider>
            <el-form-item label="前白蛋白">
              <el-input v-model="diagnose.checkout.前白蛋白" name="前白蛋白"/>
            </el-form-item>
            <el-form-item label="总蛋白">
              <el-input v-model="diagnose.checkout.总蛋白" name="总蛋白"/>
            </el-form-item>
            <el-form-item label="白蛋白">
              <el-input v-model="diagnose.checkout.白蛋白" name="白蛋白"/>
            </el-form-item>
            <el-form-item label="球蛋白">
              <el-input v-model="diagnose.checkout.球蛋白" name="球蛋白"/>
            </el-form-item>
            <el-form-item label="白蛋白/球蛋白">
              <el-input v-model="diagnose.checkout.白蛋白球蛋白" name="白蛋白球蛋白"/>
            </el-form-item>
            <el-form-item label="总胆红素">
              <el-input v-model="diagnose.checkout.总胆红素" name="总胆红素"/>
            </el-form-item>
            <el-form-item label="直接胆红素">
              <el-input v-model="diagnose.checkout.直接胆红素" name="直接胆红素"/>
            </el-form-item>
            <el-form-item label="间接胆红素">
              <el-input v-model="diagnose.checkout.间接胆红素" name="间接胆红素"/>
            </el-form-item>
            <el-form-item label="丙氨酸转移酶">
              <el-input v-model="diagnose.checkout.丙氨酸转移酶" name="丙氨酸转移酶"/>
            </el-form-item>
            <el-form-item label="天门冬氨酸转移酶">
              <el-input v-model="diagnose.checkout.天门冬氨酸转移酶" name="天门冬氨酸转移酶"/>
            </el-form-item>
            <el-form-item label="γ-谷氨酰转肽酶">
              <el-input v-model="diagnose.checkout.γ谷氨酰转肽酶" name="γ谷氨酰转肽酶"/>
            </el-form-item>
            <el-form-item label="胆碱酯酶">
              <el-input v-model="diagnose.checkout.胆碱酯酶" name="胆碱酯酶"/>
            </el-form-item>
            <el-form-item label="总胆汁酸">
              <el-input v-model="diagnose.checkout.总胆汁酸" name="总胆汁酸"/>
            </el-form-item>
            <el-divider content-position="left">心肌酶谱</el-divider>
            <el-form-item label="肌酸激酶">
              <el-input v-model="diagnose.checkout.肌酸激酶" name="肌酸激酶"/>
            </el-form-item>
            <el-form-item label="肌酸激酶同工酶">
              <el-input v-model="diagnose.checkout.肌酸激酶同工酶" name="肌酸激酶同工酶"/>
            </el-form-item>
            <el-form-item label="乳酸脱氢酶">
              <el-input v-model="diagnose.checkout.乳酸脱氢酶" name="乳酸脱氢酶"/>
            </el-form-item>
            <el-divider content-position="left">肾功能</el-divider>
            <el-form-item label="血尿素">
              <el-input v-model="diagnose.checkout.血尿素" name="血尿素"/>
            </el-form-item>
            <el-form-item label="血肌酐">
              <el-input v-model="diagnose.checkout.血肌酐" name="血肌酐"/>
            </el-form-item>
            <el-form-item label="尿酸">
              <el-input v-model="diagnose.checkout.尿酸" name="尿酸"/>
            </el-form-item>
            <el-form-item label="胱抑素C">
              <el-input v-model="diagnose.checkout.胱抑素C" name="胱抑素C"/>
            </el-form-item>
            <el-form-item label="eGFR">
              <el-input v-model="diagnose.checkout.eGFR" name="eGFR"/>
            </el-form-item>
            <el-divider content-position="left">电解质</el-divider>
            <el-form-item label="钙">
              <el-input v-model="diagnose.checkout.钙" name="钙"/>
            </el-form-item>
            <el-form-item label="无机磷">
              <el-input v-model="diagnose.checkout.无机磷" name="无机磷"/>
            </el-form-item>
            <el-divider content-position="left">血脂</el-divider>
            <el-form-item label="甘油三酯">
              <el-input v-model="diagnose.checkout.甘油三酯" name="甘油三酯"/>
            </el-form-item>
            <el-form-item label="胆固醇">
              <el-input v-model="diagnose.checkout.胆固醇" name="胆固醇"/>
            </el-form-item>
            <el-form-item label="高密度脂蛋白胆固醇">
              <el-input v-model="diagnose.checkout.高密度脂蛋白胆固醇" name="高密度脂蛋白胆固醇"/>
            </el-form-item>
            <el-form-item label="低密度脂蛋白胆固醇">
              <el-input v-model="diagnose.checkout.低密度脂蛋白胆固醇" name="低密度脂蛋白胆固醇"/>
            </el-form-item>
            <el-divider content-position="left">乳酸</el-divider>
            <el-form-item label="乳酸">
              <el-input v-model="diagnose.checkout.乳酸" name="乳酸"/>
            </el-form-item>
            <el-divider content-position="left">肝炎五项</el-divider>
            <el-form-item label="甲型肝炎抗体IgM">
              <el-input v-model="diagnose.checkout.甲型肝炎抗体IgM" name="甲型肝炎抗体IgM"/>
            </el-form-item>
            <el-form-item label="丙肝抗体定性">
              <el-input v-model="diagnose.checkout.丙肝抗体定性" name="丙肝抗体定性"/>
            </el-form-item>
            <el-form-item label="丁肝抗体定性">
              <el-input v-model="diagnose.checkout.丁肝抗体定性" name="丁肝抗体定性"/>
            </el-form-item>
            <el-form-item label="戊肝抗体定性">
              <el-input v-model="diagnose.checkout.戊肝抗体定性" name="戊肝抗体定性"/>
            </el-form-item>
            <el-form-item label="庚肝抗体定性">
              <el-input v-model="diagnose.checkout.庚肝抗体定性" name="庚肝抗体定性"/>
            </el-form-item>
            <el-divider content-position="left">乙肝两对半</el-divider>
            <el-form-item label="HBsAg">
              <el-input v-model="diagnose.checkout.HBsAg" name="HBsAg"/>
            </el-form-item>
            <el-form-item label="HBsAb">
              <el-input v-model="diagnose.checkout.HBsAb" name="HBsAb"/>
            </el-form-item>
            <el-form-item label="HBeAg">
              <el-input v-model="diagnose.checkout.HBeAg" name="HBeAg"/>
            </el-form-item>
            <el-form-item label="HBeAb">
              <el-input v-model="diagnose.checkout.HBeAb" name="HBeAb"/>
            </el-form-item>
            <el-form-item label="HBcAb">
              <el-input v-model="diagnose.checkout.HBcAb" name="HBcAb"/>
            </el-form-item>
            <el-divider content-position="left">HBV DNA</el-divider>
            <el-form-item label="HBV DNA">
              <el-input v-model="diagnose.checkout.HBVDNA" name="HBVDNA"/>
            </el-form-item>
            <el-divider content-position="left">AFP</el-divider>
            <el-form-item label="AFP">
              <el-input v-model="diagnose.checkout.AFP" name="AFP"/>
            </el-form-item>
            <el-divider content-position="left">自身免疫性肝病</el-divider>
            <el-form-item label="抗核抗体">
              <el-input v-model="diagnose.checkout.抗核抗体" name="抗核抗体"/>
            </el-form-item>
            <el-form-item label="抗线粒体抗体II型">
              <el-input v-model="diagnose.checkout.抗线粒体抗体II型" name="抗线粒体抗体II型"/>
            </el-form-item>
            <el-form-item label="抗肝肾微粒体抗体-1型">
              <el-input v-model="diagnose.checkout.抗肝肾微粒体抗体1型" name="抗肝肾微粒体抗体1型"/>
            </el-form-item>
            <el-form-item label="抗可溶性肝/胰抗原">
              <el-input v-model="diagnose.checkout.抗可溶性肝胰抗原" name="抗可溶性肝胰抗原"/>
            </el-form-item>
            <el-form-item label="平滑肌抗体">
              <el-input v-model="diagnose.checkout.平滑肌抗体" name="平滑肌抗体"/>
            </el-form-item>
            <el-form-item label="抗线粒体抗体">
              <el-input v-model="diagnose.checkout.抗线粒体抗体" name="抗线粒体抗体"/>
            </el-form-item>
            <el-form-item label="肝细胞质抗体-I型">
              <el-input v-model="diagnose.checkout.肝细胞质抗体I型" name="肝细胞质抗体I型"/>
            </el-form-item>
            <el-form-item label="抗核抗体滴度">
              <el-input v-model="diagnose.checkout.抗核抗体滴度" name="抗核抗体滴度"/>
            </el-form-item>
            <el-divider content-position="left">体液免疫</el-divider>
            <el-form-item label="免疫球蛋白A">
              <el-input v-model="diagnose.checkout.免疫球蛋白A" name="免疫球蛋白A"/>
            </el-form-item>
            <el-form-item label="免疫球蛋白M">
              <el-input v-model="diagnose.checkout.免疫球蛋白M" name="免疫球蛋白M"/>
            </el-form-item>
            <el-form-item label="免疫球蛋白G">
              <el-input v-model="diagnose.checkout.免疫球蛋白G" name="免疫球蛋白G"/>
            </el-form-item>
            <el-form-item label="补体C3">
              <el-input v-model="diagnose.checkout.补体C3" name="补体C3"/>
            </el-form-item>
            <el-form-item label="补体C4">
              <el-input v-model="diagnose.checkout.补体C4" name="补体C4"/>
            </el-form-item>
            <el-divider content-position="left">铜蓝蛋白</el-divider>
            <el-form-item label="铜蓝蛋白">
              <el-input v-model="diagnose.checkout.铜蓝蛋白" name="铜蓝蛋白"/>
            </el-form-item>
            <el-divider content-position="left">血清铁三项</el-divider>
            <el-form-item label="铁">
              <el-input v-model="diagnose.checkout.铁" name="铁"/>
            </el-form-item>
            <el-form-item label="不饱和铁">
              <el-input v-model="diagnose.checkout.不饱和铁" name="不饱和铁"/>
            </el-form-item>
            <el-form-item label="转铁蛋白饱和度">
              <el-input v-model="diagnose.checkout.血清总铁结合力" name="转铁蛋白饱和度"/>
            </el-form-item>
            <el-form-item label="转铁蛋白饱和度">
              <el-input v-model="diagnose.checkout.转铁蛋白饱和度" name="转铁蛋白饱和度"/>
            </el-form-item>
            <el-divider content-position="left">铁蛋白</el-divider>
            <el-form-item label="铁蛋白">
              <el-input v-model="diagnose.checkout.铁蛋白" name="铁蛋白"/>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="检查" name="examine">
          <el-form :model="diagnose.examine" label-width="120px">
            <el-form-item label="肝胆胰脾彩超">
              <el-input v-model="diagnose.examine.肝胆胰脾彩超" name="肝胆胰脾彩超"/>
            </el-form-item>
            <el-form-item label="腹部CT">
              <el-input v-model="diagnose.examine.腹部CT" name="腹部CT"/>
            </el-form-item>
            <el-form-item label="腹部MRI">
              <el-input v-model="diagnose.examine.腹部MRI" name="腹部MRI"/>
            </el-form-item>
            <el-form-item label="肝硬度-CAP">
              <el-input v-model="diagnose.examine.肝硬度CAP" name="肝硬度CAP"/>
            </el-form-item>
            <el-form-item label="肝硬度-E值">
              <el-input v-model="diagnose.examine.肝硬度E值" name="肝硬度E值"/>
            </el-form-item>
            <el-form-item label="病理">
              <el-input v-model="diagnose.examine.病理" name="病理"/>
            </el-form-item>
          </el-form>
        </el-tab-pane>
      </el-tabs>
       <!-- 样本 -->
       <el-divider>样本</el-divider>
       <el-table :data="diagnose.samples" border style="width: 100%">
        <el-table-column prop="typeId" label="类型" width="180">
          <template #default="scope">
            <el-select v-if="scope.row.edit" v-model="scope.row.typeId" placeholder="" name="typeId">
              <el-option value="1" label="血清"/>
              <el-option value="2" label="唾液"/>
              <el-option value="3" label="血浆"/>
            </el-select>
            <span v-else>{{scope.row.typeId}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="surplus" label="余量" width="180">
          <template #default="scope">
            <el-input v-if="scope.row.edit" v-model="scope.row.surplus"></el-input>
            <span v-else>{{scope.row.surplus}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="position" label="位置" width="180">
          <template #default="scope">
            <el-input v-if="scope.row.edit" v-model="scope.row.position"></el-input>
            <span v-else>{{scope.row.position}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="serNo" label="流水号" width="180">
          <template #default="scope">
            <el-input v-if="scope.row.edit" v-model="scope.row.serNo"></el-input>
            <span v-else>{{scope.row.serNo}}</span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="140">
          <template #default="scope">
           <el-button text type="danger" size="small" @click="deleteSample(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-form-item>
        <el-button type="primary" @click="createSample">新增</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
     </el-form>
   </div>
   <PatientList :isShowDia="patientDialogVisible" @changeRow="selectRow"></PatientList>
 </el-dialog>
</template>

<script setup>
import { ref, defineProps, defineEmits, computed, onActivated, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { add, modify, getById } from '@/api/common/common'
import PatientList from '../patient/index.vue'

const dialogVisible = computed(() => props.isShow)

const patientDialogVisible = ref(false)

const currentRow = computed(() => props.row)

const activeName = ref('checkout')

const props = defineProps({
  isShow: {
    type: Boolean,
    default: false
  },
  row: {
    type: Object,
    default: () => {}
  }
})

const diagnose = ref({
  patient: {},
  cures: [],
  checkout: {},
  examine: {},
  samples: []
})
// 根据id获取数据
const selectFormStore = id => {
  console.log(id)
  getById(id, 'grk/diagnose/dto').then(res => {
    diagnose.value = res
    if (res.cures) {
      diagnose.value.cures = JSON.parse(diagnose.value.cures)
    } else {
      diagnose.value.cures = []
    }
    if (res.checkout) {
      diagnose.value.checkout = JSON.parse(diagnose.value.checkout)
    } else {
      diagnose.value.checkout = []
    }
    if (res.examine) {
      diagnose.value.examine = JSON.parse(diagnose.value.examine)
    } else {
      diagnose.value.examine = []
    }
    if (res.diagnoseId) {
      diagnose.value.diagnoseId = diagnose.value.diagnoseId.split(',')
    } else {
      diagnose.value.diagnoseId = null
    }
  })
}

const emits = defineEmits(['onCancel', 'click'])

const onCancel = () => {
  emits('diaCancel', false)
}

watch(() => {
  console.log(currentRow.value)
  if (currentRow.value.id) {
    selectFormStore(currentRow.value.id)
  }
})

const id = ref(null)

const diagnoseRef = ref(diagnose.value)

const diagnoseRules = ref({
  regNum: [
    {
      required: true,
      trigger: 'blur',
      message: '登记号不能为空'
    }
  ],
  name: [
    {
      required: true,
      trigger: 'blur',
      message: '姓名不能为空'
    }
  ],
  sex: [
    {
      required: true,
      trigger: 'blur',
      message: '性别不能为空'
    }
  ],
  phone: [
    {
      required: true,
      trigger: 'blur',
      message: '手机号码不能为空'
    }
  ],
  birthday: [
    {
      type: 'date',
      required: true,
      trigger: 'change',
      message: '出生日期不能为空'
    }
  ]
})
const onSubmit = () => {
  console.log(diagnose.value)
  // diagnose.value.birthday = diagnose.value.birthday.substr(0, 10)
  const diagnoseLast = diagnose.value
  // 构造数据
  if (diagnose.value.cures) {
    // 清除edit标记
    diagnose.value.cures.forEach(item => {
      if (item.edit) {
        delete item.edit
      }
    })
    diagnoseLast.cures = JSON.stringify(diagnose.value.cures)
  } else {
    diagnoseLast.cures = null
  }
  if (diagnose.value.checkout) {
    diagnoseLast.checkout = JSON.stringify(diagnose.value.checkout)
  } else {
    diagnoseLast.checkout = null
  }
  if (diagnose.value.examine) {
    diagnoseLast.examine = JSON.stringify(diagnose.value.examine)
  } else {
    diagnoseLast.examine = null
  }
  if (diagnose.value.diagnoseId) {
    diagnoseLast.diagnoseId = diagnose.value.diagnoseId.join(',')
  } else {
    diagnoseLast.diagnoseId = null
  }
  diagnoseLast.samples.forEach(item => {
    if (item.edit) {
      delete item.edit
    }
  })
  console.log(diagnoseLast)
  if (id.value) { // 判断id是否为空
    diagnose.value.id = id.value
    modify(diagnoseLast, id.value, 'grk/diagnose').then(res => {
      // 关闭该页面
      ElMessage.success('更新成功')
      emits('diaCancel', false)
    })
  } else {
    console.log(diagnose)
    add(diagnoseLast, 'grk/diagnose').then(res => {
      ElMessage.success('新增成功')
      emits('diaCancel', false)
    })
  }
}

const CloseDia = () => {
  emits('diaCancel', false)
}

//  const onCancel = () => {
//  emits(props.isShow, false)
//  }
const tabClick = (tab, event) => {
  console.log(tab)
}

const selectPatient = () => {
  // 显示患者选择界面
  patientDialogVisible.value = true
  console.log(1245368)
}

const selectRow = row => {
  console.log(`选择了${row}`, row)
  diagnose.value.patient = row
  patientDialogVisible.value = false
}

const createCure = () => {
  if (!diagnose.value.cures) {
    diagnose.value.cures = [{ edit: true }]
  } else {
    diagnose.value.cures.push({ edit: true })
  }
}

const createSample = () => {
  if (!diagnose.value.samples) {
    diagnose.value.samples = [{ edit: true }]
  } else {
    diagnose.value.samples.push({ edit: true })
  }
}

const deleteSample = (index, row) => {
  console.log(diagnose.value.cures)
  diagnose.value.samples.splice(index)
}

const deleteCures = (index, row) => {
  diagnose.value.cures.splice(index)
}

</script>

<style lang="scss" scoped>
.diagnose-container {
  min-height: 100%;
  width: 100%;
  .diagnose-form {
    position: relative;
    width: 90%;
    max-width: 100%;
    top: 50px;
    left: 40px;
  }
}

.demo-tabs > .el-tabs__content {
  padding: 32px;
  color: #6b778c;
  font-size: 32px;
  font-weight: 600;
}
</style>
